<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Math</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="language.basic.syntax.html" title="Chapter 3. Basic Syntax">
<link rel="prev" href="language.syntax.quotes.html" title="Embedding Vars in Double Quotes">
<link rel="next" href="language.escaping.html" title="Escaping Smarty Parsing">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Math</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.syntax.quotes.html">Prev</a> </td>
<th width="60%" align="center">Chapter 3. Basic Syntax</th>
<td width="20%" align="right"> <a accesskey="n" href="language.escaping.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Math">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.math"></a>Math</h2></div></div></div>
<p>
  Math can be applied directly to variable values.
 </p>
<div class="example">
<a name="id344692"></a><p class="title"><b>Example 3.7. math examples</b></p>
<div class="example-contents"><pre class="programlisting">

{$foo+1}

{$foo*$bar}

{* some more complicated examples *}

{$foo-&gt;bar-$bar[1]*$baz-&gt;foo-&gt;bar()-3*7}

{if ($foo+$bar.test%$baz*134232+10+$b+10)}

{$foo|truncate:"`$fooTruncCount/$barTruncFactor-1`"}

{assign var="foo" value="`$foo+$bar`"}

  </pre></div>
</div>
<br class="example-break"><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
    Although Smarty can handle some very complex expressions and syntax, it is a good rule of
    thumb to keep the template syntax minimal and focused on presentation. If you find your
    template syntax getting too complex, it may be a good idea to move the bits that do not
    deal explicitly with presentation to PHP by way of plugins or modifiers.
 </p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.syntax.quotes.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="language.basic.syntax.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.escaping.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Embedding Vars in Double Quotes </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Escaping Smarty Parsing</td>
</tr>
</table>
</div>
</body>
</html>
